package br.com.fogas.medicao.activity.dialog;

import br.com.fogas.medicao.R;
import br.com.fogas.medicao.application.Constants;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

public class DialogConfigSenhaAdm extends DialogFragment {
	
	private DialogConfigSenhaAdmListener listener;
	private EditText etConfigSenhaAtualAdm;
	
	public interface DialogConfigSenhaAdmListener {
		public void onPositiveClick(DialogFragment dialog, String senha);
		public void onNegativeClick(DialogFragment dialog, String senha);
	}
	
	public static DialogConfigSenhaAdm newInstance(DialogConfigSenhaAdmListener listener) {
		return new DialogConfigSenhaAdm()
		.setListener(listener);
	}
	
	public DialogConfigSenhaAdm setListener(DialogConfigSenhaAdmListener listener) {
		this.listener = listener;
		return this;
	}
	
	public DialogConfigSenhaAdm showDialog(FragmentManager fragmentManager) {
		show(fragmentManager, Constants.DIALOG_ALERT);
		return this;
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		LayoutInflater inflater = getActivity().getLayoutInflater();
		View layout = inflater.inflate(R.layout.config_senha_adm, null); 
		
		this.etConfigSenhaAtualAdm = (EditText) layout.findViewById(R.id.etConfigSenhaAtualAdm);
		
		Dialog dialog = new AlertDialog.Builder(getActivity())
		        .setView(layout)
				.setTitle(R.string.dialog_title_config)
				.setNegativeButton(R.string.cancelar, onNegativeClickListener)
				.setPositiveButton(R.string.confirmar, onPositiveClickListener)
				.create();
		
		return dialog;
	}
	
	DialogInterface.OnClickListener onPositiveClickListener = new DialogInterface.OnClickListener() {

		@Override
		public void onClick(DialogInterface dialog, int which) {
			listener.onPositiveClick(DialogConfigSenhaAdm.this, etConfigSenhaAtualAdm.getText().toString().trim());
		}
	};
	
	DialogInterface.OnClickListener onNegativeClickListener = new DialogInterface.OnClickListener() {

		@Override
		public void onClick(DialogInterface dialog, int which) {
			listener.onNegativeClick(DialogConfigSenhaAdm.this, etConfigSenhaAtualAdm.getText().toString().trim());
		}
	};
}
